package com.finer.service.impl;

import com.finer.dao.FinerSaleBackDao;
import com.finer.entity.sell.FinerSaleBack;
import com.finer.service.FinerSaleBackService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 销售退货单(FinerSaleBack)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:39
 */
@Service("finerSaleBackService")
public class FinerSaleBackServiceImpl implements FinerSaleBackService {
    @Resource
    private FinerSaleBackDao finerSaleBackDao;

    /**
     * 通过ID查询单条数据
     *
     * @param Id 主键
     * @return 实例对象
     */
    @Override
    public FinerSaleBack queryById(Integer Id) {
        return this.finerSaleBackDao.queryById(Id);
    }

    /**
     * 分页查询
     *
     * @param finerSaleBack 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerSaleBack> queryByPage(FinerSaleBack finerSaleBack, PageRequest pageRequest) {
        long total = this.finerSaleBackDao.count(finerSaleBack);
        return new PageImpl<>(this.finerSaleBackDao.queryAllByLimit(finerSaleBack, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerSaleBack 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleBack insert(FinerSaleBack finerSaleBack) {
        this.finerSaleBackDao.insert(finerSaleBack);
        return finerSaleBack;
    }

    /**
     * 修改数据
     *
     * @param finerSaleBack 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleBack update(FinerSaleBack finerSaleBack) {
        this.finerSaleBackDao.update(finerSaleBack);
        return this.queryById(finerSaleBack.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param Id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer Id) {
        return this.finerSaleBackDao.deleteById(Id) > 0;
    }
}
